//#define LINUX

#include <cstdio>
#include <iostream>
#include <cstdlib>

#ifdef LINUX
//#error LINUX
#include <pthread.h>
#include "lServer.h"
#include "BDD.h"

#define NB_THREAD 1
#define NUM_PORT_DEBUT 15000

#else
//#error WINDOWS
#include "wServer.h" 
#include "BDD.h"

#endif

using namespace std;

#ifdef LINUX
void *creerThreads(void *voidPortEcoute)
{
  int port = (int) voidPortEcoute;
  cout << "port d'ecoute: " << port << endl;
  Lserver s;
  s.demarrer((unsigned short int) port);

  return NULL;
}

int main(int argc, char** argv)
{
  // cout<<"testtttttttttttttttt"<<endl;
    
  /*  BDD test;
    int z=13;
   // test.GetNiveauDeVol(z);

    cout<<"resultat de la requete :" <<test.GetNiveauDeVol(218)<<endl ;
    
    test.SetNiveauDeVol(z);
    cout<<" insertion effectu� "<<endl;
    
*/
  pthread_t tid[NB_THREAD];
  int code;
  int i;

  for (i=0; i< NB_THREAD; i++)
    {
      int port = NUM_PORT_DEBUT +i;
      cout << "creation du thread avec le port: " << port << endl;
      code = pthread_create(&tid[i], NULL, creerThreads, (void *) port);
    }

  for (i=0; i< NB_THREAD; i++){
    code = pthread_join(tid[i], NULL);
  }

  return 0;
}

#else

int main(int argc, char *argv[])
{
    
// on instancie un serveur avec comme parametre le port choisi ...
    int port=atoi(argv[1]);
     cout<<"numero de por "<<port <<endl;
    wServer *MyServer = new wServer(port);
//*******************************************************************************************
 
    
   /*//tester ==> ca fonctionne correctement ...
    BDD test;
    cout<<"resultat de la requete :" <<test.GetNiveauDeVol(328)<<endl ;
    cout<<"latitude en decimale  "<<test.GetLatitudeAeo("bgaa")<<endl;
    cout<<"longitude en decimale  "<<test.GetLongitudeAeo("bgaa")<<endl;
    */
      
    
    
   
    
    
//**********************************************************************************************
	if(MyServer->init()!=0){
		cerr << "ne peut initialiser le serveur"<< endl;
		return 1;
	}
  
	if(MyServer->demarrer()!=0){
		cerr << "ne peut d�arrer le serveur"<< endl;
		return 1;
	}
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


#endif
